﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAL;
namespace BLL
{
    public class HoaDonChiTiet_BLL
    {
        DataService DB = new DataService();
        public void HoaDonCT_Edit(int Active, int CTHoaDonID,int HoaDonID,int SPID,string TenSP, int SoLuong,float DonGia, float TongTien,ref string error)
        {
            SqlParameter[] arrParam ={
                new SqlParameter("@Active", SqlDbType.Int),
                new SqlParameter("@CTHoaDonID", SqlDbType.Int),
                new SqlParameter("@HoaDonID", SqlDbType.Int),
                new SqlParameter("@SPID", SqlDbType.Int),  
                new SqlParameter("@TenSP", SqlDbType.NVarChar), 
                new SqlParameter("@SoLuong", SqlDbType.Int), 
                 new SqlParameter("@DonGia", SqlDbType.Float), 
                 new SqlParameter("@TongTien", SqlDbType.Float), 
                new SqlParameter("@error",SqlDbType.NVarChar,200)};
            arrParam[0].Value = Active;
            arrParam[1].Value = CTHoaDonID;
            arrParam[2].Value = HoaDonID;
            arrParam[3].Value = SPID;
            arrParam[4].Value = TenSP;
            arrParam[5].Value = SoLuong;
            arrParam[6].Value = DonGia;
            arrParam[7].Value = TongTien;
            arrParam[8].Direction = ParameterDirection.Output;//Luu y cho nay           
            DB.ExeCuteStoreParam("ChiTietHoaDon_Edit", arrParam);
            error = (arrParam[8].Value.ToString() + "" != "" ? arrParam[8].Value.ToString() : "");
        }
        public void HoaDonCT_Delete(int HoaDonID)
        {
            SqlParameter[] arrParam ={
                new SqlParameter("@HoaDonID", SqlDbType.Int)};
            arrParam[0].Value = HoaDonID;
            DB.ExeCuteStoreParam("ChiTietHoaDon_Delete", arrParam);
        }
        public DataTable HoaDonCT_ViewDL(int HoaDonID)
        {
            SqlParameter[] arrParam ={
                new SqlParameter("@HoaDonID", SqlDbType.Int)};
            arrParam[0].Value = HoaDonID;
            DataTable dt= DB.ViewTableParamStore("ChiTietHoaDon_ViewDL", arrParam);
            return dt;
        }
    }
}
